import { Log } from 'src/logs/log.entity';
import { Role } from 'src/roles/role.entity';
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  OneToMany,
  ManyToMany,
  JoinTable,
  OneToOne,
} from 'typeorm';
import { Profile } from './profile.entity';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  // @Column({
  //   type: 'varchar',
  //   length: 20,
  //   name: 'first_name',
  //   comment: '姓氏'
  // })
  username: string;

  @Column()
  password: string;

  @OneToMany(() => Log, (log) => log.user)
  log: Log[];

  @OneToOne(() => Profile, (profile) => profile.user)
  profile: Profile;

  @ManyToMany(() => Role, (role) => role.user)
  @JoinTable({ name: 'user_role' })
  role: Role;

  // @OneToMany(() => Role, (role) => role.user)
  // @JoinColumn([{name:'userId',referencedColumnName:'id'}])
  // @JoinTable({ name: 'user_roles', joinColumns: [{ name: 'rolesId', referencedColumnName: 'id' }], inverseJoinColumns: [{ name: 'userId',referencedColumnName:'id' }],schema:'testdb' })
  // 会建立一张中间表
  // roles: Role[];
}
